package avicit.bdp.dgs.standard.dto;

import avicit.bdp.common.base.BaseDTO;
import avicit.bdp.core.enums.DataStateEnum;
import avicit.platform6.core.annotation.log.FieldRemark;
import avicit.platform6.core.annotation.log.LogField;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import cn.afterturn.easypoi.handler.inter.IExcelModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.lang3.StringUtils;

/**
 * @author mayi 数据标准-码表
 */
@ApiModel(value = "DataStandardDTO", description = "码表")
@Table(name = "bdp_dgs_lookup_table")
public class LookupTableDto extends BaseDTO implements IExcelModel {

  private static final long serialVersionUID = 1L;

  /** 主键ID */
  @LogField
  @ApiModelProperty(value = "主键")
  @FieldRemark(column = "id", field = "id", name = "主键")
  @Column(name = "id")
  @avicit.platform6.core.annotation.log.Id
  @javax.persistence.Id
  private String id;

  /** 所属分类 */
  @LogField
  @ApiModelProperty(value = "所属分类", name = "typeId")
  @FieldRemark(column = "type_id", field = "typeId", name = "所属分类")
  private String typeId;

  /** 码表名称 */
  @Excel(name = "*名称", orderNum = "1", width = 15, needMerge = true)
  @LogField
  @ApiModelProperty(value = "码表名称", name = "name")
  @FieldRemark(column = "name", field = "name", name = "码表名称")
  private String name;

  /** 码表编码 */
  @Excel(name = "*编码", orderNum = "2", width = 15, needMerge = true)
  @LogField
  @ApiModelProperty(value = "码表编码", name = "code")
  @FieldRemark(column = "code", field = "code", name = "码表编码")
  private String code;

  @Excel(name = "*分类全路径", orderNum = "3", width = 30, needMerge = true)
  @ApiModelProperty(value = "分类全路径", name = "fullTypeName")
  @Transient
  private String fullTypeName;

  /**
   * 状态
   *
   * @see DataStateEnum
   */
  @LogField
  @ApiModelProperty(value = "状态", name = "status")
  @FieldRemark(column = "status", field = "status", name = "状态")
  private Integer status;

  /** 码值数 */
  @LogField
  @ApiModelProperty(value = "码值数", name = "valuesCount")
  @FieldRemark(column = "values_count", field = "valuesCount", name = "码值数")
  private Integer valuesCount;

  /** 描述 */
  @Excel(name = "描述", orderNum = "5", needMerge = true)
  @LogField
  @ApiModelProperty(value = "描述", name = "remark")
  @FieldRemark(column = "remark", field = "remark", name = "描述")
  private String remark;

  @ApiModelProperty(value = "状态")
  @Transient
  private String statusString;

  @ApiModelProperty(value = "分类名称")
  @Transient
  private String typeName;

  @Excel(name = "密级", orderNum = "4", width = 15)
  private String secretLevel;

  @ExcelCollection(name = "码值", orderNum = "6")
  @Transient
  private List<LookupTableValueDto> valueDtoList;

  // 校验过程中的错误信息
  @Transient private String errorMsg;

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getTypeId() {
    return typeId;
  }

  public void setTypeId(String typeId) {
    this.typeId = typeId;
  }

  public Integer getStatus() {
    return status;
  }

  public void setStatus(Integer status) {
    this.status = status;
  }

  public String getRemark() {
    return remark;
  }

  public void setRemark(String remark) {
    this.remark = remark;
  }

  public String getStatusString() {
    return statusString;
  }

  public void setStatusString(String statusString) {
    this.statusString = statusString;
  }

  public Integer getValuesCount() {
    return valuesCount;
  }

  public void setValuesCount(Integer valuesCount) {
    this.valuesCount = valuesCount;
  }

  public String getTypeName() {
    return typeName;
  }

  public void setTypeName(String typeName) {
    this.typeName = typeName;
  }

  public String getFullTypeName() {
    return fullTypeName;
  }

  public void setFullTypeName(String fullTypeName) {
    this.fullTypeName = fullTypeName;
  }

  public List<LookupTableValueDto> getValueDtoList() {
    return valueDtoList;
  }

  public void setValueDtoList(List<LookupTableValueDto> valueDtoList) {
    this.valueDtoList = valueDtoList;
  }

  @Override
  public String getErrorMsg() {
    return errorMsg;
  }

  @Override
  public void setErrorMsg(String s) {
    if (Objects.isNull(this.errorMsg)) {
      this.errorMsg = s;
    } else {
      this.errorMsg = this.errorMsg + s;
    }
  }

  @Override
  public String getLogFormName() {
    if (StringUtils.isEmpty(super.logFormName)) {
      return "数据标准-值域标准模块";
    } else {
      return super.logFormName;
    }
}

  @Override
  public String getLogTitle() {
    if (StringUtils.isEmpty(super.logTitle)) {
      return "值域标准";
    } else {
      return super.logTitle;
    }
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    LookupTableDto that = (LookupTableDto) o;
    return Objects.equals(getId(), that.getId())
        && Objects.equals(getCode(), that.getCode())
        && Objects.equals(getName(), that.getName())
        && Objects.equals(getTypeId(), that.getTypeId())
        && Objects.equals(getStatus(), that.getStatus())
        && Objects.equals(getValuesCount(), that.getValuesCount())
        && Objects.equals(getRemark(), that.getRemark());
  }

  @Override
  public int hashCode() {
    return Objects.hash(
        getId(), getCode(), getName(), getTypeId(), getStatus(), getValuesCount(), getRemark());
  }

  @Override
  public String toString() {
    return "DataLookupTableDTO{"
        + "id='"
        + id
        + '\''
        + ", code='"
        + code
        + '\''
        + ", name='"
        + name
        + '\''
        + ", typeId='"
        + typeId
        + '\''
        + ", status="
        + status
        + ", valuesCount="
        + valuesCount
        + ", remark='"
        + remark
        + '\''
        + '}';
  }
}
